
//
//  YDOACatManagerVC.swift
//  YDOAProduct
//
//  Created by YDWY on 2017/6/7.
//  Copyright © 2017年 Allen. All rights reserved.
//

import UIKit

class YDOACatManagerVC: UIViewController {

    @IBOutlet weak var segmentContr: UISegmentedControl!
    fileprivate var  oilvc : YDOAOilVC?
    fileprivate var  insuranceVC : YDOAInsuranceVC?
    override func viewDidLoad() {
        super.viewDidLoad()
        title = "车辆管理"
        self.navigationController?.navigationBar.isHidden = false
        self.automaticallyAdjustsScrollViewInsets = false
        self.edgesForExtendedLayout = .init(rawValue: 0)
    
   
        
        setupUI()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        
        
        
    }
    



}



extension YDOACatManagerVC {
    
    fileprivate func setupUI(){
        segmentContr.backgroundColor = UIColor.white
        segmentContr.tintColor = UIColor(220, 21, 110)
        segmentContr.addTarget(self, action: #selector(valueChange), for: .valueChanged)
        segmentContr.layer.borderWidth = 0
        segmentContr.layer.cornerRadius = 0


        
        let bgview  = UIView(frame: CGRect(x: 0, y: segmentContr.ym_bottomY, width: ScreenWidth, height: ScreenHeight - 92))
        oilvc = YDOAOilVC()
        self.addChildViewController(oilvc!)
        oilvc?.view.frame = CGRect(x: 0, y: 0, width: Int(ScreenWidth), height: Int(ScreenHeight - 92))
        bgview.addSubview((oilvc?.view)!)
        bgview.backgroundColor = UIColor.clear
        self.view.addSubview(bgview)
        
        
    }
    
    
    @objc private func valueChange(){

        if segmentContr.selectedSegmentIndex == 0{
            //添加子视图控制器
            oilvc = YDOAOilVC()
            self.addChildViewController(oilvc!)
                    for view1 in view.subviews {
                        if view1 == oilvc?.view || view1 == insuranceVC?.view{
                            view1.removeFromSuperview()
                        }
                    }
             oilvc?.view.frame = CGRect(x: 0, y: Int(segmentContr.ym_bottomY), width: Int(ScreenWidth), height: Int(ScreenHeight - 92))
             view.addSubview((oilvc?.view)!)
        }else{//保险
            insuranceVC = YDOAInsuranceVC()
            self.addChildViewController(insuranceVC!)
            for view1 in view.subviews {
                if view1 == oilvc?.view || view1 == insuranceVC?.view{
                    view1.removeFromSuperview()
                }
                
            }
            
            insuranceVC?.view.frame = CGRect(x: 0, y: Int(segmentContr.ym_bottomY), width: Int(ScreenWidth), height: Int(ScreenHeight - 92))
            view.addSubview((insuranceVC?.view)!)
        }
        
    }
    
    
}


